package com.hil.chain;

import java.util.ArrayList;
import java.util.List;

public class ChainManager implements IBaseTask{
    private List<IBaseTask> iBaseTaskList = new ArrayList<>();
    private int index = 0;
    public void addTask(IBaseTask iBaseTask) {
        iBaseTaskList.add(iBaseTask);
    }

    @Override
    public void doRunAction(String endFlag, IBaseTask nextTask) {
        if (iBaseTaskList.isEmpty()) {
            // 抛出异常..
            return;
        }
        if (index >= iBaseTaskList.size()) {
            return;
        }
        IBaseTask iBaseTaskResult = iBaseTaskList.get(index);
        index ++;
        iBaseTaskResult.doRunAction(endFlag, nextTask);
    }
}
